﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Windows.Forms;
using System.Xml.Linq;
using Assist;
using Autodesk.Revit.DB;
using Autodesk.Revit.DB.Electrical;
using YArchitech.LIB;
using YArchitech.LIB.YJKControls;
using YArchitech.Revit;
using YArchitech.Revit.Electric.Common;

namespace HYElectricSetting
{
    public partial class CableTrayFittingSet : System.Windows.Forms.Form, IElectricSettingItem
	{
		public CableTrayFittingSet(Autodesk.Revit.DB.Document doc)
		{
			this.InitializeComponent();
			this.doc = doc;
			this.isEdited = false;
			this.isReady = false;
		}

		private void CableTrayFittingSet_Load(object sender, EventArgs e)
		{
			this.btnAdvancedSet.Enabled = false;
			this.btnAdvancedSet.Visible = false;
			CableTrayFittingSettingData.CableTrayFittingEntitys.Clear();
			CableTrayFittingSettingData.VerticalCableTrayFittingEntity.Clear();
			this.FillCableTrayFittingEntity();
			this.FillVerticalCableTrayFittingEntity();
			this.FillCableTray();
			this.FillCableTrayType();
			this.RegisterSelEvent();
			this.isReady = true;
		}

		private void FillCableTrayFittingEntity()
		{
			this.cableTrayTypes = RevitFilter.GetElementsOfType(this.doc, typeof(CableTrayType)).ToList<Element>();
			foreach (Element element in this.cableTrayTypes)
			{
				CableTrayFittingEntity cableTrayFittingEntity = new CableTrayFittingEntity();
				CableTrayType cableTrayType = element as CableTrayType;
				ElementId id = cableTrayType.get_Parameter(BuiltInParameter.RBS_CURVETYPE_DEFAULT_HORIZONTAL_BEND_PARAM).AsElementId();
				ElementId id2 = cableTrayType.get_Parameter(BuiltInParameter.RBS_CURVETYPE_DEFAULT_ELBOWUP_PARAM).AsElementId();
				ElementId id3 = cableTrayType.get_Parameter(BuiltInParameter.RBS_CURVETYPE_DEFAULT_ELBOWDOWN_PARAM).AsElementId();
				ElementId id4 = cableTrayType.get_Parameter(BuiltInParameter.RBS_CURVETYPE_DEFAULT_TRANSITION_PARAM).AsElementId();
				ElementId id5 = cableTrayType.get_Parameter(BuiltInParameter.RBS_CURVETYPE_DEFAULT_UNION_PARAM).AsElementId();
				cableTrayFittingEntity.CableTrayType = cableTrayType.Name;
				cableTrayFittingEntity.HorizontalElbow = this.GetFittingInfo(id);
				cableTrayFittingEntity.VerticalInnerElbow = this.GetFittingInfo(id2);
				cableTrayFittingEntity.VerticalOuterElbow = this.GetFittingInfo(id3);
				cableTrayFittingEntity.Transition = this.GetFittingInfo(id4);
				cableTrayFittingEntity.Union = this.GetFittingInfo(id5);
				bool flag = cableTrayType.get_Parameter(BuiltInParameter.ALL_MODEL_FAMILY_NAME).AsString() == "带配件的电缆桥架";
				if (flag)
				{
					cableTrayFittingEntity.CableTray = "带配件的电缆桥架";
					ElementId id6 = cableTrayType.get_Parameter(BuiltInParameter.RBS_CURVETYPE_DEFAULT_TEE_PARAM).AsElementId();
					ElementId id7 = cableTrayType.get_Parameter(BuiltInParameter.RBS_CURVETYPE_DEFAULT_CROSS_PARAM).AsElementId();
					cableTrayFittingEntity.HorizontalTee = this.GetFittingInfo(id6);
					cableTrayFittingEntity.HorizontalCross = this.GetFittingInfo(id7);
				}
				else
				{
					cableTrayFittingEntity.CableTray = "无配件的电缆桥架";
				}
				CableTrayFittingSettingData.CableTrayFittingEntitys.Add(cableTrayFittingEntity);
			}
		}

		private void FillVerticalCableTrayFittingEntity()
		{
			bool flag = File.Exists(this.path);
			if (flag)
			{
				this.root = XElement.Load(this.path);
			}
			foreach (Element element in this.cableTrayTypes)
			{
				VerticalCableTrayFittingEntity verticalCableTrayFittingEntity = new VerticalCableTrayFittingEntity();
				CableTrayType ctt = element as CableTrayType;
				verticalCableTrayFittingEntity.CableTrayType = ctt.Name;
				bool flag2 = this.root != null;
				if (flag2)
				{
					List<XElement> list = (from ele in this.root.Elements()
					where ele.Name == "CableTrayType" && ele.Attribute("Type").Value == ctt.Name
					select ele).ToList<XElement>();
					bool flag3 = list.Count == 1;
					if (flag3)
					{
						List<XElement> list2 = list[0].Elements().ToList<XElement>();
						verticalCableTrayFittingEntity.LeftDownSideElbow = list2[0].Value;
						verticalCableTrayFittingEntity.RightDownSideElbow = list2[1].Value;
						verticalCableTrayFittingEntity.LeftUpSideElbow = list2[2].Value;
						verticalCableTrayFittingEntity.RightUpSideElbow = list2[3].Value;
						verticalCableTrayFittingEntity.VerticalUpTee = list2[4].Value;
						verticalCableTrayFittingEntity.VerticalDownTee = list2[5].Value;
						verticalCableTrayFittingEntity.VerticalUpSideTee = list2[6].Value;
						verticalCableTrayFittingEntity.VerticalDownSideTee = list2[7].Value;
						verticalCableTrayFittingEntity.VerticalUpCornerTee = list2[8].Value;
						verticalCableTrayFittingEntity.VerticalDownCornerTee = list2[9].Value;
						verticalCableTrayFittingEntity.VerticalUpCornerCross = list2[10].Value;
					}
				}
				CableTrayFittingSettingData.VerticalCableTrayFittingEntity.Add(verticalCableTrayFittingEntity);
			}
		}

		private void FillCableTray()
		{
			foreach (Element element in this.cableTrayTypes)
			{
				string text = element.get_Parameter(BuiltInParameter.ALL_MODEL_FAMILY_NAME).AsString();
				bool flag = !string.IsNullOrEmpty(text);
				if (flag)
				{
					bool flag2 = !this.cbxCableTray.Items.Contains(text);
					if (flag2)
					{
						this.cbxCableTray.Items.Add(text);
					}
				}
			}
			bool flag3 = this.cbxCableTray.Items.Count > 0;
			if (flag3)
			{
				this.cbxCableTray.SelectedIndex = 0;
			}
		}

		private void FillCableTrayType()
		{
			bool flag = this.cbxCableTray.Items.Count == 0;
			if (!flag)
			{
				this.cbxCableTrayType.Items.Clear();
				foreach (Element element in this.cableTrayTypes)
				{
					string text = element.get_Parameter(BuiltInParameter.ALL_MODEL_FAMILY_NAME).AsString();
					bool flag2 = !string.IsNullOrEmpty(text);
					if (flag2)
					{
						bool flag3 = text == this.cbxCableTray.SelectedItem.ToString();
						if (flag3)
						{
							bool flag4 = !this.cbxCableTrayType.Items.Contains(element.Name);
							if (flag4)
							{
								this.cbxCableTrayType.Items.Add(element.Name);
							}
						}
					}
				}
				bool flag5 = this.cbxCableTrayType.Items.Count > 0;
				if (flag5)
				{
					this.cbxCableTrayType.SelectedIndex = 0;
				}
			}
		}

		private void RegisterSelEvent()
		{
			foreach (object obj in base.Controls)
			{
				System.Windows.Forms.Control control = (System.Windows.Forms.Control)obj;
				bool flag = control is GroupBox;
				if (flag)
				{
					foreach (object obj2 in control.Controls)
					{
						System.Windows.Forms.Control control2 = (System.Windows.Forms.Control)obj2;
						bool flag2 = control2 is YJKComboBox;
						if (flag2)
						{
							YJKComboBox hycomboBox = control2 as YJKComboBox;
							hycomboBox.SelectedIndexChanged += this.cbx_SelectedIndexChanged;
						}
						bool flag3 = control2 is Button;
						if (flag3)
						{
							bool flag4 = control2.Text == "选项...";
							if (flag4)
							{
								Button button = control2 as Button;
								button.Click += this.button_Click;
							}
						}
					}
				}
			}
		}

		private void button_Click(object sender, EventArgs e)
		{
			int category = 0;
			int subCategory = 0;
			string cableTray = this.cbxCableTray.SelectedItem.ToString();
			List<Element> source = (from type in this.cableTrayTypes
			where type.Name == this.cbxCableTrayType.SelectedItem.ToString()
			select type).ToList<Element>();
			CableTrayType cableTrayType = (from ct in (from ele in source
			select ele as CableTrayType).ToList<CableTrayType>()
			where ct.get_Parameter(BuiltInParameter.ALL_MODEL_FAMILY_NAME).AsString() == cableTray
			select ct).First<CableTrayType>();
            bool flag = (int)cableTrayType.ShapeType == 1;
			if (flag)
			{
				category = 1;
			}
			else
			{
                bool flag2 = (int)cableTrayType.ShapeType == 2;
				if (flag2)
				{
					category = 2;
				}
			}
			YJKComboBox hycomboBox = null;
			Button button = sender as Button;
			string name = button.Name;
			string text = name;
			uint num = YArchitech.Revit.PrivateImplementationDetails.ComputeStringHash(text);
			if (num <= 1806103224u)
			{
				if (num != 113946616u)
				{
					if (num != 197302381u)
					{
						if (num == 1806103224u)
						{
							if (text == "btnTransition")
							{
								subCategory = 6;
								hycomboBox = this.cbxTransition;
							}
						}
					}
					else if (text == "btnHTee")
					{
						subCategory = 4;
						hycomboBox = this.cbxHTee;
					}
				}
				else if (text == "btnVInnerElbow")
				{
					subCategory = 2;
					hycomboBox = this.cbxVInnerElbow;
				}
			}
			else if (num <= 2416717256u)
			{
				if (num != 2093867299u)
				{
					if (num == 2416717256u)
					{
						if (text == "btnHElbow")
						{
							subCategory = 1;
							hycomboBox = this.cbxHElbow;
						}
					}
				}
				else if (text == "btnHCross")
				{
					subCategory = 5;
					hycomboBox = this.cbxHCross;
				}
			}
			else if (num != 2796063870u)
			{
				if (num == 3805147037u)
				{
					if (text == "btnVOuterElbow")
					{
						subCategory = 3;
						hycomboBox = this.cbxVOuterElbow;
					}
				}
			}
			else if (text == "btnUnion")
			{
				subCategory = 7;
				hycomboBox = this.cbxUnion;
			}
			List<string> list = new List<string>();
			foreach (object obj in hycomboBox.Items)
			{
				string text2 = obj.ToString();
				list.Add(text2.Split(new char[]
				{
					':'
				}).First<string>());
			}
			FittingSelect fittingSelect = new FittingSelect(this.doc, "桥架配件", "CableTrayFitting", category, subCategory, list);
			DialogResult dialogResult = fittingSelect.ShowDialog();
			bool flag3 = dialogResult == DialogResult.OK;
			if (flag3)
			{
				bool flag4 = fittingSelect.family != null;
				if (flag4)
				{
					this.FillFitting();
					FamilySymbol familySymbol = null;
					foreach (FamilySymbol familySymbol2 in fittingSelect.family.GetSymbols())
					{
						bool flag5 = familySymbol2 != null;
						if (flag5)
						{
							familySymbol = familySymbol2;
							break;
						}
					}
					hycomboBox.SelectedItem = fittingSelect.family.Name + ":" + familySymbol.Name;
				}
				else
				{
					string text3 = "";
					bool flag6 = hycomboBox.Items.Count > 0;
					if (flag6)
					{
						foreach (object obj2 in hycomboBox.Items)
						{
							bool flag7 = obj2.ToString().Contains(fittingSelect.familyName);
							if (flag7)
							{
								text3 = obj2.ToString();
								break;
							}
						}
					}
					bool flag8 = text3 != "";
					if (flag8)
					{
						hycomboBox.SelectedItem = text3;
					}
				}
			}
		}

		private void cbxCableTray_SelectedIndexChanged(object sender, EventArgs e)
		{
			this.FillCableTrayType();
			bool flag = this.cbxCableTray.SelectedItem.ToString() == "带配件的电缆桥架";
			if (flag)
			{
				this.IsSel(true);
			}
			else
			{
				this.IsSel(false);
			}
		}

		private void cbxCableTrayType_SelectedIndexChanged(object sender, EventArgs e)
		{
			this.FillFitting();
		}

		private void cbx_SelectedIndexChanged(object sender, EventArgs e)
		{
			List<Element> source = (from type in this.cableTrayTypes
			where type.Name == this.cbxCableTrayType.SelectedItem.ToString()
			select type).ToList<Element>();
			CableTrayType cableTrayType = (from ct in (from ele in source
			select ele as CableTrayType).ToList<CableTrayType>()
			where ct.get_Parameter(BuiltInParameter.ALL_MODEL_FAMILY_NAME).AsString() == this.cbxCableTray.SelectedItem.ToString()
			select ct).First<CableTrayType>();
			YJKComboBox hycomboBox = sender as YJKComboBox;
			string name = hycomboBox.Name;
			string text = hycomboBox.SelectedItem.ToString();
			foreach (CableTrayFittingEntity cableTrayFittingEntity in CableTrayFittingSettingData.CableTrayFittingEntitys)
			{
				bool flag = cableTrayFittingEntity.CableTrayType == cableTrayType.Name && cableTrayFittingEntity.CableTray == this.cbxCableTray.SelectedItem.ToString();
				if (flag)
				{
					string text2 = name;
					uint num = YArchitech.Revit.PrivateImplementationDetails.ComputeStringHash(text2);
					if (num <= 1453699000u)
					{
						if (num != 176365004u)
						{
							if (num != 1366220999u)
							{
								if (num == 1453699000u)
								{
									if (text2 == "cbxHCross")
									{
										cableTrayFittingEntity.HorizontalCross = text;
									}
								}
							}
							else if (text2 == "cbxHElbow")
							{
								cableTrayFittingEntity.HorizontalElbow = text;
							}
						}
						else if (text2 == "cbxVOuterElbow")
						{
							cableTrayFittingEntity.VerticalOuterElbow = text;
						}
					}
					else if (num <= 1975172681u)
					{
						if (num != 1744343503u)
						{
							if (num == 1975172681u)
							{
								if (text2 == "cbxVInnerElbow")
								{
									cableTrayFittingEntity.VerticalInnerElbow = text;
								}
							}
						}
						else if (text2 == "cbxUnion")
						{
							cableTrayFittingEntity.Union = text;
						}
					}
					else if (num != 3284428458u)
					{
						if (num == 3300916747u)
						{
							if (text2 == "cbxTransition")
							{
								cableTrayFittingEntity.Transition = text;
							}
						}
					}
					else if (text2 == "cbxHTee")
					{
						cableTrayFittingEntity.HorizontalTee = text;
					}
					this.IsEdited = true;
					break;
				}
			}
		}

		private string GetFittingInfo(ElementId id)
		{
			string result = null;
			bool flag = id != null && id.IntegerValue != -1;
			if (flag)
			{
				FamilySymbol familySymbol = this.doc.GetElement(id) as FamilySymbol;
				string name = familySymbol.Family.Name;
				string name2 = familySymbol.Name;
				result = name + ":" + name2;
			}
			return result;
		}

		private void IsSel(bool isTake)
		{
			this.cbxHTee.Enabled = isTake;
			this.cbxHCross.Enabled = isTake;
			this.btnHTee.Enabled = isTake;
			this.btnHCross.Enabled = isTake;
			this.btnAdvancedSet.Enabled = isTake;
		}

		private void FillFitting()
		{
			int partType = 0;
			int partType2 = 0;
			int partType3 = 0;
			int partType4 = 0;
			int partType5 = 0;
			int partType6 = 0;
			bool flag = false;
			string cableTray = this.cbxCableTray.SelectedItem.ToString();
			List<Element> source = (from type in this.cableTrayTypes
			where type.Name == this.cbxCableTrayType.SelectedItem.ToString()
			select type).ToList<Element>();
			CableTrayType cableTrayType = (from ct in (from ele in source
			select ele as CableTrayType).ToList<CableTrayType>()
			where ct.get_Parameter(BuiltInParameter.ALL_MODEL_FAMILY_NAME).AsString() == cableTray
			select ct).First<CableTrayType>();
            bool flag2 = (int)cableTrayType.ShapeType == 1;
			if (flag2)
			{
				partType = 35;
				partType2 = 36;
				partType5 = 39;
				partType6 = 40;
				bool flag3 = cableTray == "带配件的电缆桥架";
				if (flag3)
				{
					partType3 = 38;
					partType4 = 37;
					flag = true;
				}
			}
			else
			{
                bool flag4 = (int)cableTrayType.ShapeType == 2;
				if (flag4)
				{
					partType = 43;
					partType2 = 44;
					partType5 = 47;
					partType6 = 48;
					bool flag5 = cableTray == "带配件的电缆桥架";
					if (flag5)
					{
						partType3 = 46;
						partType4 = 45;
						flag = true;
					}
				}
			}
			this.fittings = RevitFilter.GetElementsOfType(this.doc, typeof(FamilySymbol)).OfCategory(BuiltInCategory.OST_CableTrayFitting).ToElements();
			this.FillFittingFamilyType(this.fittings, partType, cableTrayType, CableTrayFittingType.HorizontalElbow, this.cbxHElbow);
			this.FillFittingFamilyType(this.fittings, partType2, cableTrayType, CableTrayFittingType.VerticalInnerElbow, this.cbxVInnerElbow);
			this.FillFittingFamilyType(this.fittings, partType2, cableTrayType, CableTrayFittingType.VerticalOuterElbow, this.cbxVOuterElbow);
			this.FillFittingFamilyType(this.fittings, partType5, cableTrayType, CableTrayFittingType.Transition, this.cbxTransition);
			this.FillFittingFamilyType(this.fittings, partType6, cableTrayType, CableTrayFittingType.Union, this.cbxUnion);
			bool flag6 = flag;
			if (flag6)
			{
				this.FillFittingFamilyType(this.fittings, partType3, cableTrayType, CableTrayFittingType.HorizontalTee, this.cbxHTee);
				this.FillFittingFamilyType(this.fittings, partType4, cableTrayType, CableTrayFittingType.HorizontalCross, this.cbxHCross);
			}
			else
			{
				this.cbxHTee.Items.Clear();
				this.cbxHCross.Items.Clear();
			}
		}

		private void FillFittingFamilyType(IList<Element> fittings, int partType, CableTrayType ctt, CableTrayFittingType cft, YJKComboBox cbx)
		{
			cbx.Items.Clear();
			List<Element> list = new List<Element>();
			foreach (Element element in fittings)
			{
				FamilySymbol familySymbol = element as FamilySymbol;
				Family family = familySymbol.Family;
				bool flag = family.get_Parameter(BuiltInParameter.FAMILY_CONTENT_PART_TYPE).AsInteger() == partType;
				if (flag)
				{
					bool flag2 = cft == CableTrayFittingType.HorizontalElbow || cft == CableTrayFittingType.HorizontalTee || cft == CableTrayFittingType.HorizontalCross || cft == CableTrayFittingType.Transition || cft == CableTrayFittingType.Union;
					if (flag2)
					{
						cbx.Items.Add(family.Name + ":" + familySymbol.Name);
						list.Add(element);
					}
					else
					{
						bool flag3 = cft == CableTrayFittingType.VerticalInnerElbow || cft == CableTrayFittingType.VerticalOuterElbow;
						if (flag3)
						{
							cbx.Items.Add(family.Name + ":" + familySymbol.Name);
						}
					}
				}
			}
			foreach (Element item in list)
			{
				fittings.Remove(item);
			}
			this.SetDefaultValue(ctt, cft, cbx);
		}

		private void SetDefaultValue(CableTrayType ctt, CableTrayFittingType cft, YJKComboBox cbx)
		{
			foreach (CableTrayFittingEntity cableTrayFittingEntity in CableTrayFittingSettingData.CableTrayFittingEntitys)
			{
				bool flag = cableTrayFittingEntity.CableTrayType == ctt.Name && cableTrayFittingEntity.CableTray == this.cbxCableTray.SelectedItem.ToString();
				if (flag)
				{
					switch (cft)
					{
					case CableTrayFittingType.HorizontalElbow:
						this.SelectDefaultValue(cbx, cableTrayFittingEntity.HorizontalElbow);
						break;
					case CableTrayFittingType.VerticalInnerElbow:
						this.SelectDefaultValue(cbx, cableTrayFittingEntity.VerticalInnerElbow);
						break;
					case CableTrayFittingType.VerticalOuterElbow:
						this.SelectDefaultValue(cbx, cableTrayFittingEntity.VerticalOuterElbow);
						break;
					case CableTrayFittingType.HorizontalTee:
						this.SelectDefaultValue(cbx, cableTrayFittingEntity.HorizontalTee);
						break;
					case CableTrayFittingType.HorizontalCross:
						this.SelectDefaultValue(cbx, cableTrayFittingEntity.HorizontalCross);
						break;
					case CableTrayFittingType.Transition:
						this.SelectDefaultValue(cbx, cableTrayFittingEntity.Transition);
						break;
					case CableTrayFittingType.Union:
						this.SelectDefaultValue(cbx, cableTrayFittingEntity.Union);
						break;
					}
					break;
				}
			}
		}

		private void SelectDefaultValue(YJKComboBox cbx, string sel)
		{
			bool flag = !string.IsNullOrEmpty(sel);
			if (flag)
			{
				cbx.SelectedItem = sel;
			}
		}

		private void btnAdvancedSet_Click(object sender, EventArgs e)
		{
			VerticalCableTrayFittingEntity fittingEntity = CableTrayFittingSettingData.VerticalCableTrayFittingEntity.Find((VerticalCableTrayFittingEntity fitting) => fitting.CableTrayType == this.cbxCableTrayType.SelectedItem.ToString());
			using (CableTrayFittingAdvancedSet cableTrayFittingAdvancedSet = new CableTrayFittingAdvancedSet(this.doc, this, fittingEntity))
			{
				DialogResult dialogResult = cableTrayFittingAdvancedSet.ShowDialog();
				bool flag = DialogResult.OK == dialogResult;
				if (flag)
				{
					foreach (VerticalCableTrayFittingEntity verticalCableTrayFittingEntity in CableTrayFittingSettingData.VerticalCableTrayFittingEntity)
					{
						bool flag2 = verticalCableTrayFittingEntity.CableTrayType == cableTrayFittingAdvancedSet.fittingEntity.CableTrayType;
						if (flag2)
						{
							verticalCableTrayFittingEntity.LeftDownSideElbow = cableTrayFittingAdvancedSet.fittingEntity.LeftDownSideElbow;
							verticalCableTrayFittingEntity.RightDownSideElbow = cableTrayFittingAdvancedSet.fittingEntity.RightDownSideElbow;
							verticalCableTrayFittingEntity.LeftUpSideElbow = cableTrayFittingAdvancedSet.fittingEntity.LeftUpSideElbow;
							verticalCableTrayFittingEntity.RightUpSideElbow = cableTrayFittingAdvancedSet.fittingEntity.RightUpSideElbow;
							verticalCableTrayFittingEntity.VerticalUpTee = cableTrayFittingAdvancedSet.fittingEntity.VerticalUpTee;
							verticalCableTrayFittingEntity.VerticalDownTee = cableTrayFittingAdvancedSet.fittingEntity.VerticalDownTee;
							verticalCableTrayFittingEntity.VerticalUpSideTee = cableTrayFittingAdvancedSet.fittingEntity.VerticalUpSideTee;
							verticalCableTrayFittingEntity.VerticalDownSideTee = cableTrayFittingAdvancedSet.fittingEntity.VerticalDownSideTee;
							verticalCableTrayFittingEntity.VerticalUpCornerTee = cableTrayFittingAdvancedSet.fittingEntity.VerticalUpCornerTee;
							verticalCableTrayFittingEntity.VerticalDownCornerTee = cableTrayFittingAdvancedSet.fittingEntity.VerticalDownCornerTee;
							verticalCableTrayFittingEntity.VerticalUpCornerCross = cableTrayFittingAdvancedSet.fittingEntity.VerticalUpCornerCross;
							break;
						}
					}
				}
				else
				{
					bool flag3 = DialogResult.Cancel == dialogResult;
					if (flag3)
					{
						Transaction transaction = new Transaction(this.doc, "DelFitting");
						transaction.Start();
						foreach (ElementId elementId in cableTrayFittingAdvancedSet.loadFittingIds)
						{
							this.doc.Delete(elementId);
						}
						this.doc.Regenerate();
						transaction.Commit();
					}
				}
			}
		}

		public bool IsEdited
		{
			get
			{
				return this.isEdited;
			}
			set
			{
				this.isEdited = value;
				HYElectricSettingMainForm hyelectricSettingMainForm = base.Tag as HYElectricSettingMainForm;
				bool flag = this.isReady && this.isEdited && hyelectricSettingMainForm != null;
				if (flag)
				{
					hyelectricSettingMainForm.ValidApplyButton();
				}
			}
		}

		public void SaveElectricSettingData()
		{
			CableTrayFittingSettingData.SaveCableTrayFittingSettingData(this.doc, this.path, this.root, this.cableTrayTypes);
		}

		private Document doc = null;

		private bool isEdited = false;

		private bool isReady = false;

		public List<Element> cableTrayTypes = new List<Element>();

		public IList<Element> fittings = null;

		public string path = Path.Combine(Product.WorkingLocation, "CableTrayFittingSet.xml");

		public XElement root = null;
	}
}
